#coding=utf-8

def pop_sort(data):
    """
    冒泡排序的算法实现
    :param list:
    :return:
    """
    # for index, i in enumerate(data[:-1]):
    #     if i > data[index+1]:
    #         data[index], data[index+1] = data[index+1], i

    for i in xrange(len(data)-1):
        for j in xrange(len(data)-i-1):
            if data[j] > data[j+1]:
                data[j], data[j+1] = data[j+1], data[j]

    return data


def binary_search(data, num):
    i = len(data)/2
    if len(data) == 1 and data[0] != num:
        return 'cant find the num %d' % num
    elif data[i] < num:
        return binary_search(data[i:], num)
    elif data[i] > num:
        return binary_search(data[:i], num)
    elif data[i] == num:
        return data[i]



data = pop_sort([4,6,109,56,1,2,5,3,456,34,123])
print binary_search(data, 57)
